package com.example.chat.controller;

import com.example.chat.service.XingHuoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

@Controller
public class XingHuoController extends TextWebSocketHandler {

    @Autowired
    private XingHuoService xingHuoService;

    @Override
    public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        String question = message.getPayload();
        xingHuoService.sendRequest(question, session);
    }

    @GetMapping("/chat")
    public String getChatPage() {
        return "chat";  // 返回到一个视图名称，例如 chat.html
    }
}
